/*
 * get_tcpcb.c
 *
 *  Created on: 2009-5-14
 *      Author: tian
 */
#include"mytcp.h"

int isequal_sockaddr(struct sockaddr *a,struct sockaddr *b){
	if(isequal(&(a->my_ip),&(b->my_ip))==0)
		return 0;
	if(isequal(&(a->peer_ip),&(b->peer_ip))==0)
		return 0;
	if(a->my_port!=b->my_port)
		return 0;
	if(a->peer_port!=b->peer_port)
		return 0;
	return 1;
}

struct tcpcb* get_tcpcb(struct sockaddr *psockaddr){
	struct tcpcb *p=head;
	while(p!=NULL){
		if(isequal_sockaddr(&(p->sock_addr),psockaddr))
			break;
		p=p->next;
	}
	if(p==NULL)
		return NULL;
	else
		return p;
}

struct tcpcb* get_tcpcb_by_sock(pid_t pid,int sock){
	struct tcpcb *p=head;
	while(p!=NULL){
		if(p->pid==pid&&p->sock==sock)
			break;
		p=p->next;
	}
	if(p==NULL)
		return NULL;
	else
		return p;
}
